﻿// <copyright file="TagsDymanicNodeProvider.cs" company="Clever Software">
// Copyright (c) 2013, 2014 All Right Reserved, http://www.cleversoftware.by
//
// This source is subject to the Microsoft Permissive License.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Clever Software</author>
// <email>info@cleversoftware.by</email>
// <date>2014-02-04</date> 
// <summary>CleverCMS source code</summary>

namespace CleverCMS.Cms.Services.Infrastructure
{
    using MvcSiteMapProvider;
    using System;
    using System.Linq;
    using System.Collections.Generic;

    using CleverCMS.Core.Infrastructure;

    public class TagsDymanicNodeProvider : DynamicNodeProviderBase
    {
        //private BlogEntryService _blogEntryService;
        private PageService _pageService;
        private readonly AppCache appCache;

        public TagsDymanicNodeProvider()
        {
            this.appCache = new AppCache();
        }

        public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
        {
            if (appCache.Exists("Tags"))
                return (List<DynamicNode>)appCache.Get("Tags");

            //_blogEntryService = IoC.Get<BlogEntryService>();
            _pageService = IoC.Get<PageService>();
            var nodes = new List<DynamicNode>();

            //var tags = _blogEntryService.GetAllTags().ToList();
            //foreach (var tag in tags)
            //{
            //    int count = _pageService.GetTagCount(tag.Id);
            //    for (int i = 0; i <= count; i++)
            //    {
            //        var tagNode = new DynamicNode { Key = "tag_" + Guid.NewGuid(), Title = tag.Name };
            //        tagNode.RouteValues.Add("tag", tag.Name);
            //        if (i != 0)
            //        {
            //            tagNode.RouteValues.Add("page", i);
            //        }
            //        tagNode.Action = "Index";
            //        tagNode.Controller = "Blog";
            //        nodes.Add(tagNode);
            //    }
            //}

            appCache.Add("Tags", nodes);
            return nodes;
        }
    }
}
